package modelLayer;
import java.util.ArrayList;

/**
 * The overall description of the DVD
 * 
 * @author Gruppe E
 * @version 1.0
 */
public class DVD
{
    private String barcode;
    private String title;
    private String artist;
    private String publicationDate;
    private ArrayList<Copy> copies;
    

    /**
     * Constructor for objects of class DVD
     */
    public DVD(String barcode, String title, String artist, String publicationDate)
    {
        copies = new ArrayList<Copy>();
        this.barcode = barcode;
        this.title = title;
        this.artist = artist;
        this.publicationDate = publicationDate;
    }
    
    /**
     * Method addCopy
     *
     * @param c A parameter
     */
    public void addCopy(Copy c)
    {
        copies.add(c);
    }
    
    /**
     * Method findCopy
     * 
     * This method will search for a serialnumber, and return the corresponding copy
     *
     * @param serial number
     * @return the correct copy
     */
    public Copy findCopy(String serialNumber)
    {
        Copy returnCopy = null;
        boolean found = false;
        int size = copies.size();
        for(int i = 0;  i < size && !found;i++)
        {
            if(copies.get(i).getSerialNumber().equals(serialNumber))
            {
                returnCopy = copies.get(i);
                found = true;
            }
        }
        return returnCopy;
    }
    
    /**
     * Method deleteCopy
     * 
     * deletes a Copy that matches the given serial number
     *
     * @param serialNumber A parameter
     * @return The return value
     */
    public boolean deleteCopy(String serialNumber)
    {
        boolean successful = true;
        if(findCopy(serialNumber)==null)
        {
            successful = false;
        }
        Copy tempC = findCopy(serialNumber);
        copies.remove(tempC);

        return successful;
    }
    
    /**
     * Method updateCopy
     *
     * searches for the copy's serial number, and updates the copy's information
     *
     * @param oldSerialNumber A parameter
     * @param purchaseDate A parameter
     * @param purchasePrice A parameter
     * @param dvd A parameter
     * @param newSerialNumber A parameter
     * @return The return value
     */
    public boolean updateCopy(String oldSerialNumber, String purchaseDate, int purchasePrice, String newSerialNumber, boolean state)
    {
        boolean successful = false;
        Copy tempC = findCopy(oldSerialNumber);
        //tempC.setDvd(dvd);
        tempC.setPurchaseDate(purchaseDate);
        tempC.setPurchasePrice(purchasePrice);
        tempC.setSerialNumber(newSerialNumber);
        tempC.setState(state);
        if(tempC.getPurchaseDate().equals(purchaseDate) && tempC.getPurchasePrice()==purchasePrice && tempC.getSerialNumber().equals(newSerialNumber) && tempC.getState()==state)
        {
            successful = true;
        }
        return successful;
    }
    
    /**
     * Method setBarcode
     *
     * @param barcode A parameter
     */
    public void setBarcode(String barcode)
    {
        this.barcode = barcode;
    }
    
    /**
     * Method setTitle
     *
     * @param title A parameter
     */
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    /**
     * Method setArtist
     *
     * @param artist A parameter
     */
    public void setArtist(String artist)
    {
        this.artist = artist;
    }
    
    /**
     * Method setPublicationDate
     *
     * @param publicationDate A parameter
     */
    public void setPublicationDate(String publicationDate)
    {
        this.publicationDate = publicationDate;
    }
    
    /**
     * Method getBarcode
     *
     * @return The return value
     */
    public String getBarcode()
    {
        return barcode;
    }
    
    /**
     * Method getTitle
     *
     * @return The return value
     */
    public String getTitle()
    {
        return title;
    }
    
    /**
     * Method getArtist
     *
     * @return The return value
     */
    public String getArtist()
    {
        return artist;
    }
    
    /**
     * Method getPublicationDate
     *
     * @return The return value
     */
    public String getPublicationDate()
    {
        return publicationDate;
    }

}
